<?php defined('SYSPATH') or die(); ?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>返佣比例和金额-思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css,base2.css,plist.css'); }
    <link type="text/css" href="{$GLOBALS['cfg_plugin_finance_public_url']}css/fx_base.css" rel="stylesheet"/>
    <link type="text/css" href="{$GLOBALS['cfg_plugin_finance_public_url']}css/fx_product.css" rel="stylesheet"/>
    <script type="text/javascript" src="/tools/js/artDialog/dist/dialog-min.js"></script>
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.buttonbox.js,choose.js,artDialog/dist/dialog-min.js"); }
    {php echo Common::getCss('ui-dialog.css','js/artDialog/css/'); }

</head>
<body style="overflow:hidden">
<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:hidden">
            <div class="cfg-header-bar">
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
            </div>
            <div class="cfg-search-bar" id="search_bar">
                <span class="select-box w150 mt-3 ml-10 fl">
                    <select class="select" id="channel_list" onchange="channelSet()">
                        {loop $channel_list $channel}
                        <option value="{$channel['id']}">{$channel['title']}</option>
                        {/loop}
                    </select>
                </span>
                <span class="select-box w150 mt-3 ml-10 fl">
                    <select class="select" id="type_list" onchange="searchData()">
                        {loop $type_list $type}
                        <option value="{$type['id']}" {if $type['id']==$type_id}selected="selected"{/if}>{$type['modulename']}</option>
                        {/loop}
                    </select>
                </span>
                <div class="select-box w150 mt-3 ml-10 fl">
                    <select class="select" id="supplier_list" onchange="searchData()">
                        <option value="">供应商</option>
                        {loop $supplier_list $supplier}
                        <option value="{$supplier['id']}">{$supplier['suppliername']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="select-box w150 mt-3 ml-10 fl">
                    <select class="select" id="settlement_list" onchange="searchData()">
                        <option value="1">结算价结算</option>
                        <option value="2">销售价结算</option>
                    </select>
                </div>
                <div class="cfg-header-search">
                    <input type="text" id="searchkey" value="" placeholder="产品标题/套餐标题" class="search-text">
                    <a href="javascript:;" class="search-btn" onclick="searchData()">搜索</a>
                </div>
            </div>
            <div id="product_grid_panel" class="content-nrt">

            </div>
        </td>
    </tr>
</table>
<script>
    window.display_mode = 1;	//默认显示模式
    window.product_kindid = 0;  //默认目的地ID
    var type_id = "{$type_id}";

    Ext.onReady(
        function () {
            Ext.tip.QuickTipManager.init();

            $(".btnbox").buttonBox();

            $("#searchkey").focusEffect();
            //添加按钮
            //产品store
            window.product_store = Ext.create('Ext.data.Store', {
                fields: [
                    'id',
                    'lineid',
                    'title',
                    'suitname',
                    'settlement_name',
                    'settlement_type',
                    'commission_mode'
                ],
                proxy: {
                    type: 'ajax',
                    extraParams: {type_id: type_id,settlement_id:1},
                    api: {
                        read: SITEURL + '{$prefix_url}/commission/batch_set_commission/action/read/',  //读取数据的URL
                        update: SITEURL + '{$prefix_url}/commission/batch_set_commission/action/save/',
                        destroy: SITEURL + '{$prefix_url}/commission/batch_set_commission/action/delete/'
                    },
                    reader: {
                        type: 'json',   //获取数据的格式
                        root: 'lists',
                        totalProperty: 'total'
                    }
                },
                remoteSort: true,
                autoLoad: true,
                pageSize: 30,
                listeners: {
                    load: function (store, records, successful, eOpts) {
                        if (!successful) {
                            ST.Util.showMsg("{__('norightmsg')}", 5, 1000);
                        }
                        var pageHtml = ST.Util.page(store.pageSize, store.currentPage, store.getTotalCount(), 10);
                        $("#line_page").html(pageHtml);
                        window.product_grid.doLayout();

                        $(".pageContainer .pagePart a").click(function () {
                            var page = $(this).attr('page');
                            product_store.loadPage(page);
                        });
                    }
                }
            });

            //产品列表
            window.product_grid = Ext.create('Ext.grid.Panel', {
                store: product_store,
                renderTo: 'product_grid_panel',
                border: 0,
                bodyBorder: 0,
                bodyStyle: 'border-width:0px',
                scroll: 'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "",
                    items: [
                        {
                            xtype: 'panel',
                            id: 'listPagePanel',
                            html: '<div id="line_page"></div>'
                        },
                        {
                            xtype: 'combo',
                            fieldLabel: '每页显示数量',
                            width: 170,
                            labelAlign: 'right',
                            forceSelection: true,
                            value: 30,
                            store: {fields: ['num'], data: [{num: 30}, {num: 60}, {num: 100}]},
                            displayField: 'num',
                            valueField: 'num',
                            listeners: {
                                select: CHOOSE.changeNum
                            }
                        }

                    ],
                    listeners: {
                        single: true,
                        render: function (bar) {
                            var items = this.items;
                            bar.insert(0, Ext.create('Ext.panel.Panel', {
                                border: 0,
                                html: '<div class="panel_bar">' +
                                    '<a class="btn btn-primary radius mr-5" href="javascript:void(0);" onclick="CHOOSE.chooseDiff()">全选</a>' +
                                    '<a class="btn btn-primary radius ml-5" href="javascript:void(0);" onclick="commissionSet()">佣金设置</a>' +
                                    '</div>'
                            }));
                            bar.insert(1, Ext.create('Ext.toolbar.Fill'));
                        }
                    }
                }),
                columns: [
                    {
                        text: '选择',
                        width: '10%',
                        tdCls: 'product-ch',
                        align: 'center',
                        dataIndex: 'id',
                        border: 0,
                        menuDisabled: true,
                        renderer: function (value, metadata, record) {
                            var id = record.get('id');
                            return "<input type='checkbox' class='product_check' id='box_" + id + "' style='cursor:pointer' value='" + value + "'/>";
                        }
                    },
                    {
                        text: '产品名称',
                        width: '30%',
                        dataIndex: 'title',
                        align: 'left',
                        menuDisabled: true,
                        border: 0,
                        sortable: false,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                    {
                        text: '套餐名称',
                        width: '30%',
                        dataIndex: 'suitname',
                        align: 'left',
                        menuDisabled: true,
                        border: 0,
                        sortable: false,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                    {
                        text: '结算方式',
                        width: '15%',
                        dataIndex: 'settlement_name',
                        align: 'left',
                        menuDisabled: true,
                        border: 0,
                        sortable: false,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                    {
                        text: '抽佣方式',
                        width: '15%',
                        dataIndex: 'commission_mode',
                        align: 'left',
                        menuDisabled: true,
                        border: 0,
                        sortable: false,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                ],
                listeners: {
                    boxready: function () {
                        var height = Ext.dom.Element.getViewportHeight();
                        this.maxHeight = height - 106;
                        this.doLayout();
                    },
                    afterlayout: function (grid) {
                        if (window.product_kindname) {
                            //Ext.getCmp('column_lineorder').setText(window.product_kindname+'-排序')
                        } else {
                            //Ext.getCmp('column_lineorder').setText('排序')
                        }

                        var data_height = 0;
                        try {
                            data_height = grid.getView().getEl().down('.x-grid-table').getHeight();
                        } catch (e) {
                        }
                        var height = Ext.dom.Element.getViewportHeight();

                        if (data_height > height - 106) {
                            window.has_biged = true;
                            grid.height = height - 106;
                        } else if (data_height < height - 106) {
                            if (window.has_biged) {
                                window.has_biged = false;
                                grid.doLayout();
                            }
                        }
                    }
                },
                plugins: [
                    Ext.create('Ext.grid.plugin.CellEditing', {
                        clicksToEdit: 2,
                        listeners: {
                            edit: function (editor, e) {
                                return false;
                            },
                            beforeedit: function (editor, e) {

                            }
                        }
                    })
                ],
                viewConfig: {}
            });


        })

    //实现动态窗口大小
    Ext.EventManager.onWindowResize(function () {
        var height = Ext.dom.Element.getViewportHeight();
        var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
        if (data_height > height - 106)
            window.product_grid.height = (height - 106);
        else
            delete window.product_grid.height;
        window.product_grid.doLayout();
    })

    $("#fx_products").change(function () {
        var type_id = $(this).val();
        var url = SITEURL + '{$prefix_url}/index/config_commission_product/type_id/' + type_id + '/parentkey/finance/itemid/5{if $menuid}/menuid/{$menuid}{/if}';
        window.location.href = url;
    });

    function channelSet()
    {
        var channel_id  = $("#channel_list").val();
        var obj = $("#type_list");
        if(channel_id==2){
            var type_id = $("#type_list").val();
            var arr = ['1','2','5','114'];
            obj.find('option').each(function (){
                var val = $(this).val();
                if($.inArray(val,arr)=='-1'){
                    $(this).hide();
                }else{
                    $(this).show();
                }
            });
            if($.inArray(type_id,arr)=='-1'){
                obj.find("option").eq(0).prop('selected','selected');
            }
        }else if(channel_id==3){
            obj.find("[value='2']").prop('selected','selected');
            obj.find("[value='2']").siblings().hide();
        }else{
            obj.find("option").show();
        }
        searchData();
    }

    function commissionSet()
    {
        var settlement_id = $("#settlement_list").val();
        var channel_id    = $("#channel_list").val();
        var type_id       = $("#type_list").val();
        var suit_id       = [];
        var title         = settlement_id==1?"设置结算价加价":"设置销售价抽佣";
        $('.product_check:checked').each(function (){
            suit_id.push($(this).val());
        });
        if(suit_id.length<1){
            ST.Util.showMsg('请至少选择一个产品套餐！',5,1500);
            return false;
        }
        suit_id = JSON.stringify(suit_id);
        console.log(suit_id);
        CHOOSE.setSome(
            title,
            {
                maxHeight:500,
                width:350,
                loadWindow:window,
                loadCallback:commissionSetCallback
            },
            SITEURL+'commission/dialog_commission_set?settlement_id='+settlement_id+'&type_id='+type_id+'&suit_id='+suit_id+'&channel_id='+channel_id,
            1
        )
    }
    function commissionSetCallback()
    {
        searchData();
    }

    function searchData() {
        var keyword       = $("#searchkey").val();
        var supplier_id   = $("#supplier_list").val();
        var channel_id    = $("#channel_list").val();
        var type_id       = $("#type_list").val();
        var settlement_id = $("#settlement_list").val();
        window.product_store.getProxy().setExtraParam('keyword', keyword);
        window.product_store.getProxy().setExtraParam('supplier_id', supplier_id);
        window.product_store.getProxy().setExtraParam('channel_id', channel_id);
        window.product_store.getProxy().setExtraParam('type_id', type_id);
        window.product_store.getProxy().setExtraParam('settlement_id', settlement_id);
        window.product_store.loadPage(1);
    }

</script>
<!--右侧选中效果-->
<script type="text/javascript" src="{$GLOBALS['cfg_plugin_finance_public_url']}js/common.js"></script>

</body>
</html>
